<?php
#添加商品
session_start();
require_once('connect.php');
$id = $_GET['id'];
$num = $_GET['num'];
$car = $_SESSION['car'] ?? array();
$res = mysqli_query($link,"select * from tb_shangpin where id = '$id'");
$row = mysqli_fetch_array($res);
if(array_key_exists($id,$car)){
    $car[$id]['num'] += $num ;
}else{
    $car[$id] = array(
        'id' => $id,
        'num' => $num,
        'name' => $row['name']
    );
}
$_SESSION['car'] = $car;
header("location:shoppingCar.php");